package com.echo.im.engin.netty.processor.preprocessor;


import com.echo.im.common.dto.MessageDTO;
import com.echo.im.engin.packet.MessagePacket;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: echo
 * @time: 2024-08-22
 */
@Component
@RequiredArgsConstructor
public class PreprocessorContext {

    public final List<MessageInPreprocessor> preprocessors;

    public void doPreprocess(MessageDTO<? extends MessagePacket> messageDTO){
        preprocessors.stream()
                .filter(preprocessor -> preprocessor.support(messageDTO.getPacket().getType()))
                .findFirst()
                .ifPresent(preprocessor -> preprocessor.doPreprocess(messageDTO));
    }

}
